//
//  RNUserDefaults.m
//  NativeAddRN
//
//  Created by 曹阳 on 17/5/8.
//  Copyright © 2017年 9elephas. All rights reserved.
//

#import "RNUserDefaults.h"

#import <RCTBridge.h>

@implementation RNUserDefaults

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(objectForKey:(NSString *)key callback:(RCTResponseSenderBlock)callback)
{
    id value = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    if(!value){
        value = @"";
    }
    callback(@[value]);
}

RCT_EXPORT_METHOD(setObject:(id)obj forKey:(NSString *)key)
{
    [[NSUserDefaults standardUserDefaults] setObject:obj forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

@end
